package filter;

import filter.pojo.Person;
import filter.service.Criteria;
import filter.service.impl.CriteriaFemaleImpl;
import filter.service.impl.CriteriaMaleImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO 过滤器模式（Filter Pattern）或标准模式（Criteria Pattern）是一种设计模式，这种模式允许开发人员使用不同的标准来过滤一组对象，通过逻辑运算以解耦的方式把它们连接起来。这种类型的设计模式属于结构型模式，它结合多个标准来获得单一标准。
 *
 */
public class demo {
    public static void main(String[] args) {
        ArrayList<Person> list = new ArrayList<>();
        list.add(new Person("金卓1",12,"male"));
        list.add(new Person("金卓2",22,"male"));
        list.add(new Person("金卓3",23,"male"));
        list.add(new Person("金卓4",24,"female"));
        list.add(new Person("金卓5",25,"female"));
        list.add(new Person("金卓6",35,"female"));
        Criteria criteria = new CriteriaFemaleImpl();
        List<Person> filter = criteria.filter(list);
        criteria = new CriteriaMaleImpl();
        List<Person> filter1 = criteria.filter(list);
        list.clear();
        filter.clear();
        filter1.clear();
    }
}
